package com.szt.sy.config.session;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.DefaultCookieSerializer;

/***
 * spring session配置
 *
 * @author wwy
 *
 */
@Configuration
@EnableRedisHttpSession
public class SpringSessionConfiguration {
	
	@Value("${server.session.cookie.max-age}")
	private Integer maxAge;
	
	/****
	 * 配置session策略
	 *
	 * @return
	 */
	@Bean
	public CookieAndHeaderHttpSessionStrategy httpSessionStrategy() {
		DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
		cookieSerializer.setCookieMaxAge(maxAge);
		CookieAndHeaderHttpSessionStrategy sessionStrategy = new CookieAndHeaderHttpSessionStrategy();
		sessionStrategy.cookieHttpSessionStrategy.setCookieSerializer(cookieSerializer);
		return sessionStrategy;
	}
	
}
